<html>
<head><meta charset="utf-8"><title>To try or not to try? · t-libs/wg-allocators · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/index.html">t-libs/wg-allocators</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html">To try or not to try?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="183853143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853143">(Dec 19 2019 at 15:03)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> pointed out, that the current <code>Abort</code> trait isn't a good choice. An allocator should not determine, how collection should handle errors. Instead, the collection needs to express this itself. <br>
We came up with a solution of another generic argument <code>Vec&lt;T, A, OomBehavior&gt;</code>. The third parameter will probably be changed to <code>const E: OomBehavior</code> where <code>enum OomBehavior { Error, Abort }</code>, as soon as default arguments are available for const generics. </p>
<p>This way it's even possible to change the behavior of collection, without touching any allocator at all. <br>
I like to try this out in <code>alloc-wg</code>, but there are two possibilites of implementing this:</p>
<ol>
<li>depending on the generic, the return type of allocator aware function change.</li>
<li>both collection has <code>try_</code> methods like <code>try_reserve</code>, but only <code>Vec&lt;_, _, OomBehavior::Abort&gt;</code> has methods like <code>reserve</code> (without <code>try_</code>)</li>
</ol>
<p>Both solutions has advantages and downsides. </p>
<ol>
<li>
<p>Solution</p>
<ul>
<li>
<p>advantages:</p>
<ul>
<li>We already express in the <code>Vec</code> type, how OOM should be handled. No need to to type <code>try_</code> everytime.<br>
First solution </li>
</ul>
</li>
<li>
<p>downsides:</p>
<ul>
<li><code>Vec</code> with different <code>OomBehavior</code> isn't interchangable, as signatures are not identical</li>
<li>We will need a way to convert from <code>Vec&lt;_, _, OomBehavior::Abort&gt;</code>to <code>Vec&lt;_, _, OomBehavior::Error&gt;</code> in order to call a method returning a result instead of abort . This could be done via <code>Into</code>, <code>AsRef</code>, and <code>AsMut</code></li>
</ul>
</li>
</ul>
</li>
<li>
<p>Solution: basically the opposite of the first solutions advantages and downsides</p>
</li>
</ol>
<p>What do you think is the better solution? Why?</p>



<a name="183853301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853301">(Dec 19 2019 at 15:04)</a>:</h4>
<blockquote>
<p>Vec with different OomBehavior isn't interchangable, as signatures are not identical</p>
</blockquote>
<p>What do you mean with interchangeable? If I have some code doing infallible allocations, and I change the Vec type to "become" fallible, then that code would still mostly compile on many cases, but warn, due to the <code>#[must_use]</code> on the results.</p>



<a name="183853363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853363">(Dec 19 2019 at 15:05)</a>:</h4>
<p>For most methods that allocate (or all?), the return type changes from <code>()</code> to <code>Result&lt;(),...&gt;</code></p>



<a name="183853490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853490">(Dec 19 2019 at 15:06)</a>:</h4>
<p>One cannot replace the vector type in code that is handling those errors, with one that does not produce errors.</p>



<a name="183853512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853512">(Dec 19 2019 at 15:06)</a>:</h4>
<p>One can do that with <code>Abort</code> in that direction, but not in the other.</p>



<a name="183853652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853652">(Dec 19 2019 at 15:08)</a>:</h4>
<p>You forget the methods returning a value or <code>Self</code> like <code>Vec::with_capacity</code></p>



<a name="183853663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853663">(Dec 19 2019 at 15:08)</a>:</h4>
<p>I think it would be worth it to explore to which point interchangeability solves useful problems, and then once we have some concrete examples, maybe evaluate how to improve them.</p>



<a name="183853678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853678">(Dec 19 2019 at 15:08)</a>:</h4>
<p>Hm, yes, <code>with_capacity</code> wouldn't work.</p>



<a name="183853693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853693">(Dec 19 2019 at 15:08)</a>:</h4>
<p>I'd like to go with the first solution, but I like to hear other people's opinion :)</p>



<a name="183853733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853733">(Dec 19 2019 at 15:09)</a>:</h4>
<p>Notice that if you have a <code>Vec</code> with an allocator that uses <code>Abort</code>, and call <code>Vec::push</code>, and then try to interchange the vector type with an allocator that does not implement <code>Abort</code>, the code stops compiling as well.</p>



<a name="183853756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853756">(Dec 19 2019 at 15:09)</a>:</h4>
<p>Because this new <code>Vec</code> only supports <code>Vec::try_push</code>, and not <code>Vec::push</code></p>



<a name="183853832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853832">(Dec 19 2019 at 15:10)</a>:</h4>
<p>So I don't think there is a proposed solution that's fully interchangeable.</p>



<a name="183853846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853846">(Dec 19 2019 at 15:10)</a>:</h4>
<p>However, if you write all your code with <code>Vec::try_</code>, then it works for all allocators.</p>



<a name="183853909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853909">(Dec 19 2019 at 15:11)</a>:</h4>
<p>When changing from Abort to Error, it should always fail to compile. That's why you want to change it.<br>
I think interchangeability isn't a major point anyway here</p>



<a name="183853962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853962">(Dec 19 2019 at 15:12)</a>:</h4>
<p>I think you are onto something with interchangeability.</p>



<a name="183853992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183853992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183853992">(Dec 19 2019 at 15:12)</a>:</h4>
<p>I just wish we had some concrete examples collected somewhere. It might be easier to look at the impact of the different approaches by just trying them out in small snippets.</p>



<a name="183854065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183854065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183854065">(Dec 19 2019 at 15:13)</a>:</h4>
<p>Currently, most people don't care about OOM. It occures rarely in the common use case and it's hard to handle in std</p>



<a name="183854080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183854080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183854080">(Dec 19 2019 at 15:13)</a>:</h4>
<p>So finding an example project will be hard</p>



<a name="183854205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183854205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183854205">(Dec 19 2019 at 15:15)</a>:</h4>
<p>But you can throw the new vector in nearly all crates and watch the compile errors :D</p>



<a name="183886976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183886976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183886976">(Dec 19 2019 at 21:26)</a>:</h4>
<p>I found another advantage for the first solution: It's possible to extend this, when adding more behaviors like <code>Panic</code> or <code>Option</code>. We could even go crazy and implement the behavior on the trait itself. This would correspond to something like "policy-based design" described by Andrei Alexandrescu in "Modern C++ Design"</p>



<a name="183887359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183887359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183887359">(Dec 19 2019 at 21:31)</a>:</h4>
<p>However, I think implementing the behavior on the trait requires GATs for the return type</p>



<a name="183897469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183897469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183897469">(Dec 19 2019 at 23:58)</a>:</h4>
<p>I think 2 is better</p>



<a name="183897480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183897480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183897480">(Dec 19 2019 at 23:59)</a>:</h4>
<p>No GATs and better inference</p>



<a name="183897496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183897496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183897496">(Dec 19 2019 at 23:59)</a>:</h4>
<p>And easy to write the abort ones in terms of the <code>try_</code> ones.</p>



<a name="183897518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183897518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183897518">(Dec 19 2019 at 23:59)</a>:</h4>
<p>GATs are not required in either solutions</p>



<a name="183897704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183897704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183897704">(Dec 20 2019 at 00:01)</a>:</h4>
<p><span class="user-mention" data-user-id="220594">@John Ericson</span> What do you think about using a generic parameter in general instead of the <code>Alloc</code> trait?</p>



<a name="183898587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183898587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183898587">(Dec 20 2019 at 00:16)</a>:</h4>
<p>Yes that is better. It is indeed not a property of the allocator</p>



<a name="183898650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183898650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183898650">(Dec 20 2019 at 00:17)</a>:</h4>
<p>But of the collection</p>



<a name="183898705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183898705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183898705">(Dec 20 2019 at 00:18)</a>:</h4>
<p>And a collection can pass the parameter to another type it uses, just like it does work the allocator</p>



<a name="183906566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183906566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183906566">(Dec 20 2019 at 03:37)</a>:</h4>
<p>I think OOM is hard to handle because we make it hard to handle</p>



<a name="183906573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183906573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183906573">(Dec 20 2019 at 03:37)</a>:</h4>
<p>and probably most OOM isn't like actual exhausted memory, but an accidentally crazy amount of memory being requested</p>



<a name="183923167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183923167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183923167">(Dec 20 2019 at 10:12)</a>:</h4>
<p>I found another downside for the First solution: the documentation <del>is bloated up</del> gets messy, as every allocating method is listed twice with the same name, and the signature of the <code>impl</code> block is hard to notice - even with a doc-comment. This probably will lead to a lot of confusion, esp. for unexperimented users.</p>



<a name="183923195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183923195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183923195">(Dec 20 2019 at 10:13)</a>:</h4>
<p>I guess I will implement both on <code>alloc-wg</code> on different branches</p>



<a name="183992920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/183992920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#183992920">(Dec 21 2019 at 03:17)</a>:</h4>
<p>With my own crates I've found it a useful pattern for the non-try version to just say "As <code>try_foo</code> but it unwraps the failure." or something very curt like that. You could probably do a similar thing here and just say that the OOM handler is triggered on failure.</p>



<a name="184022240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184022240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184022240">(Dec 21 2019 at 19:14)</a>:</h4>
<p>That's what I already do, but when two methods are called the same, it's hard to track, which method is implemented on which behavior (although it's intuitive, that the <code>Error</code>-variant will return a <code>Result</code>). The more I play around with it or think about it, the more I like the second solution (try-variants)</p>



<a name="184024103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024103">(Dec 21 2019 at 20:13)</a>:</h4>
<p>Yeah just become <em>extremely</em> rigid with the naming convention. Every <code>foo</code> op is likely to be just</p>
<div class="codehilite"><pre><span></span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">args</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Out</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="n">try_foo</span><span class="p">(</span><span class="n">args</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">.</span><span class="n">unwrap_or_else</span><span class="p">(</span><span class="o">||</span><span class="w"> </span><span class="n">handle_alloc_error</span><span class="p">())</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>And then all the thinking happens in the <code>try</code> variant.</p>



<a name="184024159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024159">(Dec 21 2019 at 20:14)</a>:</h4>
<p>Hehe well handle_alloc_error needs the layout</p>



<a name="184024179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024179">(Dec 21 2019 at 20:15)</a>:</h4>
<p>That is why we should probably return <code>Result&lt;T, (Alloc:Error, NonZeroLayout)&gt;</code></p>



<a name="184024225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024225">(Dec 21 2019 at 20:16)</a>:</h4>
<p>And then we literally will do the same thing every time</p>



<a name="184024232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024232">(Dec 21 2019 at 20:16)</a>:</h4>
<p>And can write a macro for it</p>



<a name="184024875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024875">(Dec 21 2019 at 20:36)</a>:</h4>
<p>That's why we have <code>CollectionAllocError</code>, which stores the layout where necessary</p>



<a name="184024888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024888">(Dec 21 2019 at 20:37)</a>:</h4>
<p>Right but things like Box don't use it, because no capacity stuff</p>



<a name="184024893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024893">(Dec 21 2019 at 20:37)</a>:</h4>
<p>Maybe we need to call what we have VecLikeCollectionError</p>



<a name="184024939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024939">(Dec 21 2019 at 20:38)</a>:</h4>
<p>And make the OOM variant be CollectionAllocError which is basically the tuple</p>



<a name="184024941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024941">(Dec 21 2019 at 20:38)</a>:</h4>
<p>And add the From instance</p>



<a name="184024947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024947">(Dec 21 2019 at 20:38)</a>:</h4>
<p>Collections that use Box will especially benefit</p>



<a name="184024955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184024955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184024955">(Dec 21 2019 at 20:39)</a>:</h4>
<p>Same for those that use Rc and Arc</p>



<a name="184066067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184066067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184066067">(Dec 22 2019 at 19:24)</a>:</h4>
<p>Hmm, <code>OomBehavior</code>? <code>OomPolicy</code>? <code>OomHandling</code>?</p>



<a name="184066627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184066627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184066627">(Dec 22 2019 at 19:38)</a>:</h4>
<p>if it's "handle alloc error" and we have an "oom handler", then "oom handling" fits the other names so far.</p>



<a name="184066634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184066634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184066634">(Dec 22 2019 at 19:39)</a>:</h4>
<p>is <code>handle_alloc_error</code> stable?</p>



<a name="184066645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184066645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184066645">(Dec 22 2019 at 19:39)</a>:</h4>
<p>yeah <a href="https://doc.rust-lang.org/std/alloc/fn.handle_alloc_error.html" target="_blank" title="https://doc.rust-lang.org/std/alloc/fn.handle_alloc_error.html">https://doc.rust-lang.org/std/alloc/fn.handle_alloc_error.html</a> ?</p>



<a name="184066714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/184066714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#184066714">(Dec 22 2019 at 19:40)</a>:</h4>
<p>Okay, then <code>OomHandling</code> sounds right</p>



<a name="185038498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185038498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185038498">(Jan 07 2020 at 18:24)</a>:</h4>
<p><span class="user-mention" data-user-id="216785">@Tim Diekmann</span> </p>
<blockquote>
<p>This would correspond to something like "policy-based design" described by Andrei Alexandrescu in "Modern C++ Design"</p>
</blockquote>
<p>The line between policy-based design being a good or bad idea in practice is thin. The whole point of the policy is to change some behavior, but if the "semantics" of most type methods depend on the actual policy, then it gets hard to learn what a method actually does.</p>



<a name="185038574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185038574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185038574">(Jan 07 2020 at 18:25)</a>:</h4>
<p>I think for this particular use case its fine, since the policy controls whether some methods exist or not.</p>



<a name="185038598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185038598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185038598">(Jan 07 2020 at 18:25)</a>:</h4>
<p>And not the "behavior" of these methods, so that the docs of the methods does not depend on the policy.</p>



<a name="185038713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185038713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185038713">(Jan 07 2020 at 18:26)</a>:</h4>
<p>In the Rust API docs, depending whether we follow the <code>try_X</code> vs two different <code>X</code> approaches, things might be easier or harder to document.</p>



<a name="185038938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185038938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185038938">(Jan 07 2020 at 18:28)</a>:</h4>
<p>E.g. if we go with the</p>
<div class="codehilite"><pre><span></span><span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">A</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">OomAbort</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// Doc for the abort on OOM version</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">push</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">T</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">A</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">OomHandling</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// Doc for the &quot;result-returning&quot; version</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">push</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">T</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="p">()</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>approach, we end up with two <code>push</code> functions in the API docs, with two different doc strings, etc.</p>



<a name="185039261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185039261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185039261">(Jan 07 2020 at 18:32)</a>:</h4>
<blockquote>
<p>But you can throw the new vector in nearly all crates and watch the compile errors :D</p>
</blockquote>
<p>Notice that one can write code that is polymorphic over these, one sometimes doesn't even need traits, eg.,  <code>let _ = vec.push();</code> will work in both cases.</p>



<a name="185039323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185039323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185039323">(Jan 07 2020 at 18:33)</a>:</h4>
<p>For the more general case of taking a collection polymorphically, and propagating errors in the "collection-preferred" way (using panics, or using results), then that's going to need some generics plumbing.</p>



<a name="185039438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185039438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185039438">(Jan 07 2020 at 18:34)</a>:</h4>
<p>But that's the case for both strategies (e.g. <code>try_</code> has the same problem).</p>



<a name="185041957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185041957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185041957">(Jan 07 2020 at 18:58)</a>:</h4>
<p>If <code>?</code> worked on <code>()</code> type values and simply always became <code>()</code> without the possibility of early return, then it would also let people write <code>v.push()?;</code> for both handling and panicing vecs</p>



<a name="185044678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185044678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185044678">(Jan 07 2020 at 19:24)</a>:</h4>
<p>That would be an interesting extension</p>



<a name="185044908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185044908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185044908">(Jan 07 2020 at 19:26)</a>:</h4>
<p>but I don't think this extends to the rest of APIs, e.g., <code>Vec::pop() -&gt; T</code>, where you wouldn't be able to write <code>v.pop()?</code> in both cases.</p>



<a name="185049230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185049230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185049230">(Jan 07 2020 at 20:06)</a>:</h4>
<p>but isn't pop always an <code>Option&lt;T&gt;</code>? Any vec can be empty</p>



<a name="185050780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/To%20try%20or%20not%20to%20try%3F/near/185050780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/To.20try.20or.20not.20to.20try.3F.html#185050780">(Jan 07 2020 at 20:22)</a>:</h4>
<p>hmm, duh, bad example</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>